home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Utilities / RemoteCommand / Source / execServer.subproj / _askop.m next >
Encoding:
Text File  |  1993-06-09  |  2.6 KB  |  90 lines

  1. // -------------------------------------------------------------------------------------
  2. // _askop
  3. // Establishes remote-object connection with main app to ask operator questions
  4. // -------------------------------------------------------------------------------------
  5. // Permission is granted to freely redistribute this source code, and to use fragments
  6. // of this code in your own applications if you find them to be useful.  This class/module,
  7. // along with the source code, come with no warranty of any kind, and the user assumes
  8. // all responsibility for its use.
  9. // -------------------------------------------------------------------------------------
  10.  
  11. #import <mach/mach.h>
  12. #import <stdio.h>
  13. #import <strings.h>
  14. #import <libc.h>
  15. #import <remote/NXConnection.h>
  16. #import <appkit/Application.h>
  17. #import "AskOperator.h"
  18.  
  19. @interface _RmtMethods : Object
  20. - (const char*)getResponseForMessage:(askOperator_t*)ao;
  21. @end
  22.  
  23. void main (int argc, char *argv[])
  24. {
  25.     int                i;
  26.     BOOL            doAskOp = YES;
  27.     askOperator_t    askop;
  28.     id                ss;
  29.     char            *host, *server;
  30.     
  31.     /* check proper arg count */
  32.     if (argc < 3) {
  33.         int a;
  34.         
  35.         /* make sure we're starting on a new line */
  36.         fprintf(stderr, "\n");
  37.         
  38.         /* print command as specified */
  39.         fprintf(stderr, "%s", argv[0]);
  40.         for (a = 1; a < argc; a++) fprintf(stderr, " \"%s\"", argv[a]);
  41.         fprintf(stderr, "\n");
  42.         
  43.         /* print usage */
  44.         fprintf(stderr,
  45.             "usage: %s [-hhost] title msg [b1 [b2 [b3 [b4]]]]\n", argv[0]);
  46.             
  47.         /* exit */
  48.         exit(1);
  49.         
  50.     }
  51.  
  52.     /* defaults */
  53.     memset(&askop, 0, sizeof(askop));
  54.     askop.type = 0;
  55.  
  56.     /* parse: askop -hmandi "Title" "Message" "B1" "B2" "B3" "B4" */
  57.     for (i = 1; i < argc; i++) {
  58.         if (*argv[i] != '-') break;
  59.         switch (argv[i][1]) {
  60.             case 'n':    // don't ask-op
  61.                 doAskOp = NO;
  62.                 break;
  63.             case 'h':    // remote host name
  64.                 strcpy(askop.host, &argv[i][2]);
  65.                 break;
  66.         }
  67.     }
  68.     if (i < argc) strcpy(askop.title    , argv[i++]);
  69.     if (i < argc) strcpy(askop.message  , argv[i++]);
  70.     if (i < argc) strcpy(askop.button[0], argv[i++]); else askop.type = 1;
  71.     if (i < argc) strcpy(askop.button[1], argv[i++]);
  72.     if (i < argc) strcpy(askop.button[2], argv[i++]);
  73.     if (i < argc) strcpy(askop.button[3], argv[i++]);
  74.  
  75.     /* establish connection */
  76.     if (!(server = getenv("SERVERNAME")) || !*server) server = ASK_SERVER;
  77.     host = (*askop.host? askop.host : getenv("SERVERHOST"));
  78.     if (host && !*host) host = (char*)nil;
  79.     [NXConnection setDefaultTimeout:-1];
  80.     if (!(ss = [NXConnection connectToName:server onHost:host])) {
  81.         fprintf(stderr, "%s: Cannot connect to server '%s' on host '%s'\n", argv[0],
  82.                 server, (host?host:"<local>"));
  83.         exit(1);
  84.     }
  85.  
  86.     /* print results */
  87.     if (doAskOp) printf("%s\n", [ss getResponseForMessage:&askop]);
  88.     
  89. }
  90.